﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 第二次作业
{
    public class ATM
    {
        public event EventHandler<BigMoneyArgs> BigMoneyFetched;
        private creditAccount currentAccount;
        private Random random = new Random();
        public ATM(creditAccount currentAccount)
        {
            this.currentAccount = currentAccount;
        }

        public void Withdraw(decimal amount)
        {
            if (random.Next(0, 100) < 30)
                throw new BadCashException("有坏钞票");

            currentAccount.fetch(amount);

            if (amount > 10000)
                OnBigMoneyFetched(new BigMoneyArgs(currentAccount, amount));
        }

        protected virtual void OnBigMoneyFetched(BigMoneyArgs e)
        {
            BigMoneyFetched?.Invoke(this, e);
        }
    }
    public class BadCashException : Exception
    {
        public BadCashException(string message) : base(message) { }
    }
}
